<?php

class orderModel extends Model
{

	public function genorderid($orderid,$time)
	{
		return 'PA1000'.date('YmdHis',$time).str_pad($orderid,6,'0',STR_PAD_LEFT);
	}

	public function decodeorderid($orderid)
	{
		return intval(substr($orderid,-6));
	}

	public function getlist()
	{
		$list=(array)$this->select();
		foreach($list as &$v){
			$v=$this->dataAppend($v);
		}
		return $list;
	}

	public function dataAppend($arr)
	{
		$arr['order_id']=M('order')->genorderid($arr['id'],$arr['create_time']);
		if ($arr['type']=='app'){
			$arr['url_goods']=U('user.app.detail',array('appid'=>M('app')->genappid($arr['type_id'])));
		}
		return $arr;
	}

	public function getinfo($orderid)
	{
		$where['id']=$this->decodeorderid($orderid);
		$info=$this->where($where)->find();
        if ($info){
            return $this->dataAppend($info);
        }else{
            return array();
        }

	}
}